﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class WorkTime_MendWorkOn : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitializeComponent();

            Master.DataSource = WMaster;

            if (Request.Params["A"] != null)
                spBtnSave2WorkOn.Visible = true;
            else
                spBtnSave2WorkOn.Visible = false;


            MasterPage_MasterPage mpg = (MasterPage_MasterPage)this.Page.Master;
            mpg.HelpHref = "";
            mpg.PageName = "考勤补时单";
            mpg.PicUrl = "";
            mpg.IntiBar();
        }
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WorkTime_MendWorkOn));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = true;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        this.WMaster.RemoteName = "SWorkTime.WT_MendWorkOn";
        this.WMaster.ServerModify = true;
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected object GetOnDuty()
    {
        return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 8, 30, 0);
    }

    protected object GetOffDuty()
    {
        return new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 17, 0, 0);
    }

    protected string GetEmpId()
    {
        String str = Srvtools.CliUtils.GetValue("_UserCode")[1].ToString();
        str = int.Parse(str).ToString();
        return str;
    }

    //protected bool Disp()
    //{
    //    if (Request.Params["A"] != null)
    //        return true;
    //    else
    //        return false;
    //}

    //protected void WebFormView1_DataBound(object sender, EventArgs e)
    //{
    //    if (this.WebFormView1.CurrentMode == FormViewMode.ReadOnly)
    //    {            
    //        if (Request.Params[""] != null)
    //        {
    //            Button btnMend = (Button)this.WebFormView1.FooterRow.FindControl("Button1");
    //            btnMend.Visible = true;
    //        }
    //    }
    //}
    //protected void WebFormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
    //{
    //    if (e.CommandName == "MendWorOn")
    //    {
    //        Srvtools.WebRefVal wrvEmpId = (Srvtools.WebRefVal)this.WebFormView1.Row.FindControl("EmpIdTextBox");
    //        BaseText.ZLTextBox ztbOnDuty = (BaseText.ZLTextBox)this.WebFormView1.Row.FindControl("OnDutyTextBox");
    //        BaseText.ZLTextBox ztbOffDuty = (BaseText.ZLTextBox)this.WebFormView1.Row.FindControl("OffDutyTextBox");
    //        if (wrvEmpId != null && ztbOnDuty != null && ztbOffDuty != null)
    //        {
    //            object[] objParam = new object[3];
    //            objParam[0] = wrvEmpId.BindingValue;
    //            objParam[1] = ztbOnDuty.GetDateTime.ToString();
    //            objParam[2] = ztbOffDuty.GetDateTime.ToString();

    //            object[] myRet = Srvtools.CliUtils.CallMethod("SWorkTime", "ExecMendWorkOn", objParam);
    //            if (myRet != null && (int)myRet[0] == 0)
    //            {
    //                bool boo = (bool)myRet[1];
    //                if (boo)
    //                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('已成功添加考勤数据')", true);
    //                else
    //                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('添加失败！请联系管理员！')", true);
    //            }
    //        }
    //    }
    //}
    protected void BtnSave2WorkOn_Click(object sender, EventArgs e)
    {
        Srvtools.WebRefVal wrvEmpId = (Srvtools.WebRefVal)this.WebFormView1.Row.FindControl("EmpIdTextBox");
        BaseText.ZLTextBox ztbOnDuty = (BaseText.ZLTextBox)this.WebFormView1.Row.FindControl("OnDutyTextBox");
        BaseText.ZLTextBox ztbOffDuty = (BaseText.ZLTextBox)this.WebFormView1.Row.FindControl("OffDutyTextBox");
        if (wrvEmpId != null && ztbOnDuty != null && ztbOffDuty != null)
        {
            object[] objParam = new object[3];
            objParam[0] = wrvEmpId.BindingValue;
            objParam[1] = ztbOnDuty.GetDateTime.ToString();
            objParam[2] = ztbOffDuty.GetDateTime.ToString();

            object[] myRet = Srvtools.CliUtils.CallMethod("SWorkTime", "ExecMendWorkOn", objParam);
            if (myRet != null && (int)myRet[0] == 0)
            {
                bool boo = (bool)myRet[1];
                if (boo)
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('已成功添加考勤数据')", true);
                else
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", "alert('添加失败！请联系管理员！')", true);
            }
        }

    }
}
